package com.nyist.springcloud.controller;

import com.nyist.springcloud.ResultVO;
import com.nyist.springcloud.entities.Payment;
import com.nyist.springcloud.service.PayHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author yangxiaogen
 * @date 2021/2/1 10:53
 */
@RestController
@RequestMapping("/pay/hystrix")
@Slf4j
public class PayHystixController {
    @Resource
    private PayHystrixService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/ok")
    public ResultVO<Payment> getServerPort(@RequestBody Payment payment) {
        ResultVO<Payment> paymentResultVO = new ResultVO<>();

        log.info("开始--查询--支付数据:  8006 ", serverPort);
        paymentResultVO.setCode("200"+"\t"+paymentService.paymentInfo_OK(payment.getId()));
        paymentResultVO.setMessage("成功" + serverPort);

        return paymentResultVO;
    }

    @PostMapping("/timeout")
    public ResultVO<Payment> timeoutPay(@RequestBody Payment payment) {
        ResultVO<Payment> paymentResultVO = new ResultVO<>();

        log.info("开始--查询--支付数据:  8006 ", serverPort);
        paymentResultVO.setCode("200"+"\t"+paymentService.paymentInfo_TimeOut(payment.getId()));
        paymentResultVO.setMessage("成功" + serverPort);

        return paymentResultVO;
    }
}
